#include "FeatureExtractor.h"
#include "ISpectrum.h"
#include "FEexceptions.h"
#include <map>

using namespace std;

typedef pair<SHANDLE, ISpectrum*> specPair;
typedef map<SHANDLE, ISpectrum*> specMap;
specMap objList;
int objCount = 1;

int addSpectrogram(int order, int shift, int winType, SHANDLE& handle)
{
	try
	{
		ISpectrum* obj = ISpectrum::make(_IppSpectrum());
		obj->Init(order, shift, winType);
		objList.insert(specPair(objCount, obj));
		handle = objCount++;
	}
	catch(...)
	{
		handle = 0;
		return -1;
	}

	return 0;
}

int ReleaseSpectrograms()
{
	try
	{
		specMap::iterator iter = objList.begin();
		while(iter != objList.end())
		{
			delete iter->second;
			iter++;
		}
	}
	catch(...)
	{
		return -1;
	}

	return 0;
}

int getShiftWindowsNumber(SHANDLE handle, int len, int shift, int& number)
{
	try
	{
		specMap::iterator it = objList.find(handle);
		if(it != objList.end())
		{
			number = it->second->getShiftWindowsNumber(len, shift);
		}
	}
	catch(...)
	{
		number = 0;
		return -1;
	}

	return 0;
}

int getSizeWindow(SHANDLE handle, int& number)
{
	try
	{
		specMap::iterator it = objList.find(handle);
		if(it != objList.end())
		{
			number = it->second->getSizeWindow();
		}
	}
	catch(...)
	{
		number = 0;
		return -1;
	}

	return 0;
}

class FeatureExtractor
{
protected:

	ISpectrum* pSpectrogram;
	int sizeWin;
	int order;
	int shift;

public:

	FeatureExtractor();
	virtual void Init();
	virtual void ExtractFeatures(const short* pWav, int wSize, short** ppFeatures, int fSize);
	~FeatureExtractor();
};

FeatureExtractor::FeatureExtractor():pSpectrogram(0)
{
}

void FeatureExtractor::Init()
{
	pSpectrogram = ISpectrum::make(_IppSpectrum());	
	pSpectrogram->Init(order, shift, 0);
}

void FeatureExtractor::ExtractFeatures(const short* pWav, int wSize, short** ppFeatures, int fSize)
{
}

FeatureExtractor::~FeatureExtractor()
{

}